package com.wmlive.hhvideo.heihei.beans.splash;

import com.alibaba.fastjson.JSON;
import com.wmlive.hhvideo.application.DCApplication;
import com.wmlive.hhvideo.heihei.beans.personal.ReportEntry;
import com.wmlive.hhvideo.heihei.beans.personal.ReportType;
import com.wmlive.hhvideo.utils.KLog;
import com.wmlive.hhvideo.utils.preferences.SPUtils;

import java.util.List;

/**
 * Created by vhawk on 2017/5/22.
 * Modify by lsq
 */

public class InitCatchData {
    private static final String KEY_INIT_CATCH_DATA = "INIT_CATCH_DATA";
    private static InitResponse sInitResponse;

    public static InitResponse setInitUrl(InitResponse initResponse) {
        sInitResponse = initResponse;
        return sInitResponse;
    }

    public static void saveInitData(InitResponse initResponse) {
        if (null != initResponse) {
            SPUtils.putString(DCApplication.getDCApp(), KEY_INIT_CATCH_DATA, JSON.toJSONString(initResponse));
        }
    }

    public static InitResponse getInitCatchData() {
        if (sInitResponse == null) {
            try {
                sInitResponse = JSON.parseObject(SPUtils.getString(DCApplication.getDCApp(), KEY_INIT_CATCH_DATA, ""), InitResponse.class);
                KLog.i("解析本地的init接口：" + (sInitResponse != null ? sInitResponse.toString() : "null"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return sInitResponse;
    }

    private static UserUrl getUserUrl() {
        return getInitCatchData() != null ? getInitCatchData().getUser() : null;
    }


    private static OpusUrl getOpusUrl() {
        return getInitCatchData() != null ? getInitCatchData().getOpus() : null;
    }

    private static MusicUrl getMusicUrl() {
        return getInitCatchData() != null ? getInitCatchData().getMusic() : null;
    }

    private static SocialUrl getSocialUrl() {
        return getInitCatchData() != null ? getInitCatchData().getSocial() : null;
    }

    private static TopicUrl getTopicUrl() {
        return getInitCatchData() != null ? getInitCatchData().getTopic() : null;
    }

    private static SearchUrl getSearchUrl() {
        return getInitCatchData() != null ? getInitCatchData().getSearch() : null;
    }

    private static SysUrl getSysUrl() {
        return getInitCatchData() != null ? getInitCatchData().getSys() : null;
    }

    private static Function getFunction() {
        return getInitCatchData() != null ? getInitCatchData().getFunction() : null;
    }

    //user
    public static String userGetSMSVerificationCode() {
        return getUserUrl() != null ? getUserUrl().getGetSMSVerificationCode() : null;
    }

    public static String userSignIn() {
        return getUserUrl() != null ? getUserUrl().getSignIn() : null;
    }

    public static String userSignOut() {
        return getUserUrl() != null ? getUserUrl().getSignOut() : null;
    }

    public static String userSignInCLByPhone() {
        return getUserUrl() != null ? getUserUrl().getSignInCLByPhone() : null;
    }

    public static String userUpdateUser() {
        return getUserUrl() != null ? getUserUrl().getUpdateUser() : null;
    }

    public static String userUserHome() {
        return getUserUrl() != null ? getUserUrl().getUserHome() : null;
    }

    public static String userGetUserInfo() {
        return getUserUrl() != null ? getUserUrl().getGetUserInfo() : null;
    }

    public static String userFollowUser() {
        return getUserUrl() != null ? getUserUrl().getFollowUser() : null;
    }

    public static String userUnFollowUsr() {
        return getUserUrl() != null ? getUserUrl().getUnFollowUsr() : null;
    }

    public static String userListFollower() {
        return getUserUrl() != null ? getUserUrl().getListFollower() : null;
    }

    public static String userListFans() {
        return getUserUrl() != null ? getUserUrl().getListFans() : null;
    }

    public static String userListReportType() {
        return getUserUrl() != null ? getUserUrl().getListReportType() : null;
    }

    public static String userReport() {
        return getUserUrl() != null ? getUserUrl().getReport() : null;
    }

    public static String userListUserOpus() {
        return getUserUrl() != null ? getUserUrl().getListUserOpus() : null;
    }

    public static String userListUserLike() {
        return getUserUrl() != null ? getUserUrl().getListUserLike() : null;
    }

    public static ReportEntry userReposrtList() {
        return getInitCatchData() != null ? getInitCatchData().getConf_data() : null;
    }

    //opus
    public static String opusSaveOpus() {
        return getOpusUrl() != null ? getOpusUrl().getSaveOpus() : null;
    }

    public static String opusListOpusByRecommend() {
        return getOpusUrl() != null ? getOpusUrl().getListOpusByRecommend() : null;
    }

    public static String opusListOpusByFollow() {
        return getOpusUrl() != null ? getOpusUrl().getListOpusByFollow() : null;
    }

    public static String opusListOpusByTime() {
        return getOpusUrl() != null ? getOpusUrl().getListOpusByTime() : null;
    }

    public static String opusGetOpus() {
        return getOpusUrl() != null ? getOpusUrl().getGetOpus() : null;
    }

    public static String opusViewOpus() {
        return getOpusUrl() != null ? getOpusUrl().getViewOpus() : null;
    }

    public static String opusLikeOpus() {
        return getOpusUrl() != null ? getOpusUrl().getLikeOpus() : null;
    }

    public static String opusDeleteOpus() {
        return getOpusUrl() != null ? getOpusUrl().getDeleteOpus() : null;
    }

    public static String opusCommendOpus() {
        return getOpusUrl() != null ? getOpusUrl().getCommendOpus() : null;
    }

    public static String opusListOpusComment() {
        return getOpusUrl() != null ? getOpusUrl().getListOpusComment() : null;
    }

    public static String opusDeleteComment() {
        return getOpusUrl() != null ? getOpusUrl().getDeleteComment() : null;
    }

    public static String opusListReportType() {
        return getOpusUrl() != null ? getOpusUrl().getListReportType() : null;
    }

    public static String opusReport() {
        return getOpusUrl() != null ? getOpusUrl().getReport() : null;
    }

    public static String opusManage() {
        return getOpusUrl() != null ? getOpusUrl().getManageOpus() : null;
    }

    //music
    public static String musicListOpusByMusic() {
        return getMusicUrl() != null ? getMusicUrl().getListOpusByMusic() : null;
    }

    public static String musicMyFavMusic() {
        return getMusicUrl() != null ? getMusicUrl().getMyFavMusic() : null;
    }

    public static String musicGetMusicByCat() {
        return getMusicUrl() != null ? getMusicUrl().getGetMusicByCat() : null;
    }

    public static String musicGetCategory() {
        return getMusicUrl() != null ? getMusicUrl().getGetCategory() : null;
    }

    public static String musicFavMusic() {
        return getMusicUrl() != null ? getMusicUrl().getFavMusic() : null;
    }

    public static String musicSearch() {
        return getMusicUrl() != null ? getMusicUrl().getSearch() : null;
    }

    //social
    public static String socialGetBanner() {
        return getSocialUrl() != null ? getSocialUrl().getGetBanner() : null;
    }

    //topic
    public static String topicListTopic() {
        return getTopicUrl() != null ? getTopicUrl().getListTopic() : null;
    }

    public static String topicListOpusByTopic() {
        return getTopicUrl() != null ? getTopicUrl().getListOpusByTopic() : null;
    }

    public static String topicSearch() {
        return getTopicUrl() != null ? getTopicUrl().getSearch() : null;
    }

    public static String topicCreate() {
        return getTopicUrl() != null ? getTopicUrl().getCreate() : null;
    }

    public static String newTopicCheck() {
        return getTopicUrl() != null ? getTopicUrl().getNewTopicCheck() : null;
    }

    //search
    public static String searchSearch() {
        return getSearchUrl() != null ? getSearchUrl().getSearch() : null;
    }

    //sys
    public static String sysAboutUs() {
        return getSysUrl() != null ? getSysUrl().getAboutUs() : null;
    }

    public static String sysUpdateCheck() {
        return getSysUrl() != null ? getSysUrl().getUpdateCheck() : null;
    }

    public static String sysUploadLog() {
        return getSysUrl() != null ? getSysUrl().getUploadLog() : null;
    }

    public static String sysOssToken() {
        return getSysUrl() != null ? getSysUrl().getOssToken() : null;
    }

    public static String sysServiceTerms() {
        return getSysUrl() != null ? getSysUrl().getServiceTerms() : null;
    }

    public static String sysDevicePushInfo() {
        return getSysUrl() != null ? getSysUrl().getDevicePushInfo() : null;
    }

    //function
    public static boolean functionHhlog() {
        return getFunction() != null ? getFunction().isHhlog() : false;
    }

    public static boolean functionChat() {
        return getFunction() != null ? getFunction().isChat() : false;
    }

    public static String opusLogs() {
        return getOpusUrl() != null ? getOpusUrl().getOpusLogs() : null;
    }

    //举报的类型列表
    public static List<ReportType> getReportEntry() {
        return sInitResponse != null ? (sInitResponse.getConf_data() != null ? sInitResponse.getConf_data().getReport_type() : null) : null;
    }

    public static void setReportEntry(List<ReportType> list) {
        if (null != sInitResponse) {
            if (sInitResponse.getConf_data() == null) {
                sInitResponse.setConf_data(new ReportEntry());
            }
            sInitResponse.getConf_data().setReport_type(list);
        }
    }

    //获取message对象
    public static MessageUrl getMessageObj() {
        return getInitCatchData() != null ? getInitCatchData().getMessage() : null;
    }

    /**
     * 获取websocketServer 地址
     *
     * @return
     */
    public static String getWebsocketServerUrlOfMessage() {
        return getMessageObj() != null ? getMessageObj().getWebSocketServer() : "";
    }
}
